@extends('layouts.admin')
@section('css')
    <link rel="stylesheet" href="{{ asset('static/editormd/css/editormd.min.css') }}">
    <link href="{{ asset('static/toastr/toastr.css') }}" rel="stylesheet" type="text/css" />
@endsection

@section('content')
    <div class="col-sm-9 col-sm-offset-3 col-md-10 col-lg-10 col-md-offset-2 main" id="main">
        <div class="row">
            <form action="{{ url('admin/article/store') }}" method="post" enctype="multipart/form-data">
                {{ csrf_field() }}
                <div class="col-md-9">
                    <h1 class="page-header">撰写新文章</h1>
                    <div class="form-group">
                        <label for="article-title" class="sr-only">标题</label>
                        <input type="text" value="{{ $article->title }}" id="article-title" name="title" class="form-control" placeholder="在此处输入标题"  autofocus autocomplete="off">
                    </div>
                    <div class="form-group" style="display: none;">
                        <label for="article-title" class="sr-only">id</label>
                        <input type="text" value="{{ $article->id }}" name="id" class="form-control" autofocus autocomplete="off">
                    </div>
                    <div class="form-group">
                        <label for="article-title" class="sr-only">作者</label>
                        <input type="text" value="{{ $article->author }}" id="article-author" name="author" class="form-control" placeholder="在此处输入作者"  autofocus autocomplete="off">
                    </div>
                    {{--<div class="form-group">--}}
                        {{--<label for="article-title" class="sr-only">内容</label>--}}
                        {{--<input type="text" value="{{ old('markdown') }}" id="article-markdown" name="markdown" class="form-control" placeholder="在此处输入文章内容"  autofocus autocomplete="off">--}}
                    {{--</div>--}}

                    <div class="add-article-box">
                        <h2 class="add-article-box-title"><span>关键字</span></h2>
                        <div class="add-article-box-content">
                            <input type="text"  value="{{ $article->keywords }}" class="form-control" placeholder="请输入关键字" name="keywords" autocomplete="off">
                            <span class="prompt-text">多个请用英文逗号,隔开。</span>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="category-fname">文章分类</label>
                        <select id="category-fname" class="form-control" name="category_id">
                            <option value="0" selected>无</option>
                            @foreach($cats as $v)
                                <option value="{{$v->id}}" @if($v->id==$article->category_id)selected="selected"@endif>{{$v->name}}</option>
                            @endforeach
                        </select>
                        <span class="prompt-text">分类是有层级关系的，您可以有一个“音乐”分类目录，在这个目录下可以有叫做“流行”和“古典”的子目录。</span>
                    </div>

                    <div class="form-group">
                        <label for="category-fname">标签</label>
                        @foreach($tags as $v)
                            <input type="checkbox" name="tag_ids[]" value="{{$v->id}}" @if(in_array($v->id,$old_tags))checked="checked"@endif/>{{$v->name}}&nbsp;&nbsp;
                        @endforeach
                    </div>

                    <div class="add-article-box">
                        <h2 class="add-article-box-title"><span>描述</span></h2>
                        <div class="add-article-box-content">
                            <textarea class="form-control" name="description" autocomplete="off">{{ $article->description }}</textarea>
                            <span class="prompt-text">可以不填，如不填；则截取文章内容前300字为描述</span>
                        </div>
                    </div>
                    <div class="form-group" id="editormd">
                        <textarea class="form-control" name="markdown">{{ $article->markdown }}</textarea>
                    </div>
                </div>
                <div class="col-md-3">
                    <h1 class="page-header">操作</h1>
                    <div class="add-article-box">
                        <h2 class="add-article-box-title"><span>栏目</span></h2>
                        {{--<div class="add-article-box-content">--}}
                            {{--<ul class="category-list">--}}
                                {{--<li>--}}
                                    {{--<label>--}}
                                        {{--<input name="category" type="radio" value="1" checked>--}}
                                        {{--这是栏目 <em class="hidden-md">( 栏目ID: <span>1</span> )</em></label>--}}
                                {{--</li>--}}
                                {{--<li>--}}
                                    {{--<label>--}}
                                        {{--<input name="category" type="radio" value="2">--}}
                                        {{--这是栏目 <em class="hidden-md">( 栏目ID: <span>2</span> )</em></label>--}}
                                {{--</li>--}}
                                {{--<li>--}}
                                    {{--<label>--}}
                                        {{--<input name="category" type="radio" value="3">--}}
                                        {{--这是栏目 <em class="hidden-md">( 栏目ID: <span>3</span> )</em></label>--}}
                                {{--</li>--}}
                                {{--<li>--}}
                                    {{--<label>--}}
                                        {{--<input name="category" type="radio" value="4">--}}
                                        {{--这是栏目 <em class="hidden-md">( 栏目ID: <span>4</span> )</em></label>--}}
                                {{--</li>--}}
                                {{--<li>--}}
                                    {{--<label>--}}
                                        {{--<input name="category" type="radio" value="5">--}}
                                        {{--这是栏目 <em class="hidden-md">( 栏目ID: <span>5</span> )</em></label>--}}
                                {{--</li>--}}
                            {{--</ul>--}}
                        {{--</div>--}}
                    {{--</div>--}}
                    {{--<div class="add-article-box">--}}
                        {{--<h2 class="add-article-box-title"><span>标签</span></h2>--}}
                        {{--<div class="add-article-box-content">--}}
                            {{--<input type="text" class="form-control" placeholder="输入新标签" name="tags" autocomplete="off">--}}
                            {{--<span class="prompt-text">多个标签请用英文逗号,隔开</span> </div>--}}
                    {{--</div>--}}
                    <div class="add-article-box">
                        <h2 class="add-article-box-title"><span>封面图片</span></h2>
                        <div class="add-article-box-content">
                            {{--<input type="text" class="form-control" placeholder="点击按钮选择图片" id="pictureUpload" name="titlepic" autocomplete="off">--}}
                            <img src="{{ $article->cover }}" id="showimg" alt="" style="width:100%;">
                            <input type="hidden" name="cover" value="{{ $article->cover }}">
                        </div>
                        <div class="add-article-box-footer" style="position: relative;">
                            <button class="btn btn-default" type="button" name="upImage">选择</button>
                            <input type="file" name="cover" id="cover" onchange="changepic(this)" style="display: block; float: right; position: absolute; padding: 6px 12px; width: 26.7%; right: 10px; opacity: 0;">
                        </div>
                    </div>
                    <div class="add-article-box">
                        <h2 class="add-article-box-title"><span>发布</span></h2>
                        <div class="add-article-box-content">
                            <p><label>状态：</label><span class="article-status-display">未发布</span></p>
                            {{--<p><label>公开度：</label><input type="radio" name="visibility" value="0" checked/>公开 <input type="radio" name="visibility" value="1" />加密</p>--}}
                            {{--<p><label>发布于：</label><span class="article-time-display"><input style="border: none;" type="datetime" name="time" value="2016-01-09 17:29:37" /></span></p>--}}
                        </div>
                        <div class="add-article-box-footer">
                            <button class="btn btn-primary" type="submit">发布</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
@section('js')
    <script src="{{ asset('static/editormd/editormd.min.js') }}"></script>
    <script src="{{ asset('static/toastr/toastr.js') }}"></script>
    {{--<script type="text/javascript">--}}
        {{--$(function() {--}}
            {{--var editor = editormd("editormd", {--}}
                {{--path : "{{ asset('/static/editormd/lib') }}/" // Autoload modules mode, codemirror, marked... dependents libs path--}}
            {{--});--}}

            {{--/*--}}
            {{--// or--}}
            {{--var editor = editormd({--}}
                {{--id   : "editormd",--}}
                {{--path : "../lib/"--}}
            {{--});--}}
            {{--*/--}}
        {{--});--}}
    {{--</script>--}}
    <script>
        var testEditor;

        $(function() {
            testEditor = editormd("editormd", {
                width     : "100%",
                height    : 720,
                toc       : true,
                //atLink    : false,    // disable @link
                //emailLink : false,    // disable email address auto link
                todoList  : true,
                placeholder: '输入文章内容',
                toolbarAutoFixed: false,
                path      : '{{ asset('/static/editormd/lib') }}/',
                emoji: true,
                toolbarIcons : ['undo', 'redo', 'bold', 'del', 'italic', 'quote', 'uppercase', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'list-ul', 'list-ol', 'hr', 'link', 'reference-link', 'image', 'code', 'code-block', 'table', 'emoji', 'html-entities', 'watch', 'preview', 'search', 'fullscreen'],
                imageUpload: true,
                imageUploadURL : '{{ url('admin/article/uploadImage') }}',
                theme : 'dark',
                // previewTheme : "dark",
                // editorTheme : "monokai",
            });
        });
        //上传图片预览
        function changepic() {
            var reads= new FileReader();
            f=document.getElementById('cover').files[0];
            reads.readAsDataURL(f);
            reads.onload=function (e) {
                document.getElementById('showimg').src=this.result;
            };
        }

        @if ($errors->any())
            @foreach ($errors->all() as $error)
                toastr.error("{{$error}}")
            @endforeach
        @endif

    </script>
@endsection

@stop

